<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>后台管理</title>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> 
<link href="<%=path %>/static/miniui/themes/default/demo.css" rel="stylesheet"
	type="text/css" />
<style type="text/css">
body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}
</style>

<script src="<%=path %>/static/miniui/boot.js"
	type="text/javascript"></script>

<!--引入皮肤样式-->
<link href="<%=path %>/static/miniui/themes/blue/skin.css"
	rel="stylesheet" type="text/css" />

</head>
<body> 
 <div style="width:800px;">
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-add" onclick="add()" plain="true" tooltip="增加...">增加</a>
                           <a class="mini-button" iconCls="icon-remove" onclick="remove()" plain="true">删除</a>
                      <!--   <span class="separator"></span> -->
                          <a class="mini-button" iconCls="icon-add" onclick="edit()" plain="true">编辑</a>     
                    </td>
                    <td style="white-space:nowrap;">
                   
                       <input id="key" class="mini-textbox" emptyText="发帖人" style="width:150px;" onenter="onKeyEnter"/>   
                        <a class="mini-button" onclick="search()">查询</a>
                    </td>
                </tr>
            </table>           
        </div>
    </div>   
  
<div id="datagrid1" class="mini-datagrid" style="width:800px;height:280px;" 
    url="userList"  idField="userid" allowResize="true"  dataField="list"
    sizeList="[5,20,50,100]" pageSize="20" totalField="totalField" allowCellEdit="true" allowCellSelect="true" multiSelect="true" 
        editNextOnEnterKey="true"  editNextRowCell="true"
>
    <div property="columns" id="form1"> 
            <div type="indexcolumn"> 编号</div>   
            <div type="checkcolumn"></div>
        <div  field="userid" width="100" headerAlign="center" allowSort="true">用户编号
        <!--   <input  id="userid" class="mini-spinner" style="width:100%;" minWidth="200" readonly="readonly"/> --></div>   
        <div  field="username" width="120" headerAlign="center" >用户名
      <!--  <input id="username"  class="mini-textbox" style="width:100%;" minWidth="200" /> --></div>                         
        <div  field="email" width="100" renderer="onGenderRenderer" align="center" headerAlign="center">用户的邮箱  </div>
         <div  field="nickname" width="100" renderer="onGenderRenderer" align="center" headerAlign="center">用户昵称 </div>                    
         
            <div  field="status" width="100" headerAlign="center"  renderer="onStatusRenderer">邮箱激活状态
           
             </div>
         
          <div  field="userstatus" width="100" headerAlign="center" renderer="onStatusRenderer1">用户的状态
          </div>
    </div>
</div>   
   
    <script type="text/javascript">
    mini.parse();
  
   
    var grid = mini.get("datagrid1");

   // grid.load(); 
    grid.sortBy("userid", "asc");
    var db = new mini.DataBinding();
    
    db.bindForm("form1", grid);
   
    function remove() {
        
        var rows = grid.getSelecteds();  
        if (rows.length > 0) {
            if (confirm("确定删除选中记录？")) {
                var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.postid);
                }
                var id = ids.join(',');         
                grid.loading("操作中，请稍后......");
                $.ajax({
                    url: "delete?id=" +id,
                    success: function (text) {
                        grid.reload();
                    },
                    error: function () {
                    }
                });
            }
        } else {
            alert("请选中一条记录");
        }
    }
   
     function edit() {
         
         var row = grid.getSelected();  
       
         if (row) {
             mini.open({
                 url: "<%=path%>/back/postInformation",
                 title: "编辑", width: 600, height: 360,
                 onload: function () {
                     var iframe = this.getIFrameEl();
                     var data = { action: "edit", id: row.postid };
           
                     iframe.contentWindow.SetData(data);
                     
                 },
                 ondestroy: function (action) {
                     grid.reload();
                     
                 }
             });
             
         } else {
             alert("请选中一条记录");
         }
         
     }
   function onStatusRenderer(e){
	  var grid = e.sender;
       var record = e.record; 
       var uid = record._uid;
       var rowIndex = e.rowIndex;      		
	     if(record.status==1){
	    	  var s = "<a class='Edit_Button' href='javascript:void(0)' onclick=\"statusChanges('" + record.userid +"','"+record.status+ "')\">已激活</a>";
	    	 return s;
	     }else{
	    	  var s = "<a class='Edit_Button' href='javascript:void(0)' onclick=\"statusChanges('" + record.userid +"','"+record.status+ "')\">未激活</a>";
	    	 return s;
	     }
   }
   function onStatusRenderer1(x){
	   var grid = x.sender;
       var record = x.record;
       var uid = record._uid;
       var rowIndex = x.rowIndex;  
	     if(record.userstatus==0){
	    	/*  <input id="combobox3" class="mini-combobox" style="width:150px;" textField="text" valueField="id" 
	    		    url="../data/countrys.txt" value="cn" showNullItem="true" required="true" allowInput="true"
	    		    onvalidation="onComboValidation" 
	    		/>  */ 
	    	 var s = "<a class='Edit_Button' href='javascript:void(0)' onclick=\"statusChange('" + record.userid +"','"+record.userstatus+ "')\">正常</a>";  
	    	/* var s="<input id=\'combobox3\' class=\'mini-combobox\' style=\'width:150px;\' textField=\'text\' valueField=\'id\' 
		    url=\'/data/countrys.txt\' value=\'cn\' showNullItem=\'true\' required=\'true\' allowInput=\'true\'
    		    onvalidation=\'onComboValidation\' 
    		/>"; */
	    	 return s;
	     }else if(record.userstatus==1){
	    	  var s = "<a class='Edit_Button' href='javascript:void(0)' onclick=\"statusChange('" + record.userid +"','"+record.userstatus+ "')\">禁言</a>";
	    	 return s;
	     }else{
	    	 var s = "<a class='Edit_Button' href='javascript:void(0)' onclick=\"statusChange('" + record.userid +"','"+record.userstatus+ "')\">禁用</a>";
	    	 return s;
	     }
 }
  function statusChanges(userid,status){
	
	 grid.loading("操作中，请稍后......");
      $.ajax({
          url: "statusChanges?id=" +userid+"&status="+status,
          async:true,	  
          success: function (text) {
        		var o = mini.decode(text);
        		mini.alert(o.code+"+++msg"+o.msg);
        	  if (o.code=="0101") {
        		  grid.reload();
        		  
			}
             
          },
          error: function (data) {
        	  mini.alert(data);
        	  var o = mini.decode(data);  
        	  mini.alert(o.code);
        	  mini.alert(o.msg);
        	 
          },
          complete: function(XMLHttpRequest, textStatus) {
        	  grid.load();
          }
      }); 
  }
  function statusChange(userid,userstatus){
		
		 grid.loading("操作中，请稍后......");
	      $.ajax({
	          url: "statusChange?id=" +userid+"&userstatus="+userstatus,
	          success: function (text) {
	        		var o = mini.decode(text);
	        	  if (o.code=="0101") {
	        		  grid.reload();
	        		  
				}
	             
	          },
	          error: function () {
	        	  mini.alert("服务器繁忙  ，请稍后再试！");
	          }
	      }); 
	  }

 
     function add() {
            
            mini.open({
            	 url: "<%=path%>/back/postInformation",
                title: "新增发帖信息", width: 600, height: 360,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new"};
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
       function search() {
            var key = mini.get("key").getValue();
        	grid.load({ key: key });
        }
        function onKeyEnter(e) {
            search();
        } 
       
      
    </script>
</body>
</html>